<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <%--多附件上传css--%>
    <link rel="stylesheet" href="<s:url value="/assets/css/main.css"></s:url>"/>
</head>
<body class="no-skin">
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>

<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="col-sm-offset-2" style="margin-top: 100px;">
                <form:form commandName="TaskMainFilter" cssClass="form-horizontal" role="form"  onsubmit="return false;">
                    <div class="row">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right">
                                    任务名称
                                </label>
                                <div class="col-sm-8">
                                    <input type="text"  name="mainName"  placeholder="任务名称"  value="${TaskMainFilter.mainName}"
                                           class="form-control required">
                                </div>
                            </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right">
                                任务内容
                            </label>
                            <div class="col-sm-8">
                                <textarea type="text" name="content" placeholder="任务内容"
                                       class="form-control required" style="resize: vertical;min-height: 50px;height: 80px">${TaskMainFilter.content}</textarea>
                            </div>
                        </div>
                    </div>
                   <!-- <div class="row ">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right" for="categoryId">
                                <a style="color: red">*</a>事项类型
                            </label>
                            <div class="col-sm-8">
                                <select type="text" id="categoryId" name="categoryId" placeholder="事项类型" readonly value="${TaskMainFilter.categoryId}"
                                       class="form-control required">
<%--                                    <c:forEach items="${types}" var="type">--%>
<%--                                        <option value="${type.category}">${type.category}</option>--%>
<%--                                    </c:forEach>--%>
                                </select>
                            </div>
                        </div>
                    </div> -->

                    <div class="row ">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right" >
                                督查组单位
                            </label>
                            <div class="col-sm-8">
                                <select name="" multiple="true" id="e1" onchange="addHandle(this)">
                                    <option></option>
                                    <c:forEach items="${groups}" var="group">
                                        <option value="${group.sysId}">${group.deptName}</option>
                                    </c:forEach>
                                </select>
                                <input type="hidden" value=""  name="inspectionId">
                            </div>
                        </div>
                    </div>
                    <div class="row" style="margin-top: 100px">
                        <div class="form-group">
                            <label class="col-sm-offset-1 col-sm-1 text-right control-label">任务附件</label>
                            <div class="col-sm-8 pos-rel">
                                <div id="uploader"></div>
                                <%--<div>
                                    <div style="display: inline-block">
                                        <input type="file" class="fileBorder" id="fileupload">
                                    </div>
                                    <div style="display: inline-block">
                                        <button class="btn btn-info" onclick="uploadFile(this,'gJFile','gJFileName')">
                                            <span class="glyphicon glyphicon-open"></span>上传附件
                                        </button>
                                    </div>
                                </div>--%>
                            </div>
                        </div>
                    </div>
                    <div class="row" style="margin-top: 100px">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right">
                            </label>
                            <div class="col-sm-6">
                                <input type="button" value="关闭" class="btn-sm btn-default pull-right" onclick="javascript: parent.close_current_app();" style="margin-left: 10px"/>
                                <input type="button" value="添加任务" class="btn-sm btn-info pull-right handleAdd" onclick="handleAdd()"/>
                            </div>
                        </div>
                    </div>
                    <%--多附件上传的name和id--%>
                    <input type="text" name="file" value="" hidden>
                    <input type="text" name="fileName" value="" hidden>
                </form:form>
                </div>
            </div>
        </div>
    </div>
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div>
<%--多选上传--%>
<script src="<s:url value="/assets/js/dist/easyUploader.jq.js"></s:url>"></script>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>

<script>
    <%--多文件上传--%>
    var fileStr = "";//id字符串拼接
    var fileNameStr = "";//文件名字符串拼接
    var uploader = easyUploader({
        id: "uploader",
        accept: '.jpg,.png,.doc,.docx,.pdf,.xls,.xlsx,.ppt,.pptx',
        action: '/filesUpload/uploadFiles',
        dataFormat: 'formData',
        maxCount: 10,//允许上传的个数
        maxSize: 2000,//允许上传最大的容量
        multiple: true,
        data: null,
        beforeUpload: function (file, data, args) {
        },
        onChange: function (fileList) {
        },
        onRemove: function (removedFiles, files) {
            console.log('onRemove', removedFiles);
        },
        onSuccess: function (res) {
            console.log('onSuccess', res);
            if (res.data !== undefined && res.data[0] !== undefined) {
                //拼接文件id 和 文件名
                $("input[name='file']").val(fileStr += res.data[0].sysid + ",");
                $("input[name='fileName']").val(fileNameStr += res.data[0].oldName + ",");

            }
        },
        onError: function (err) {
            console.log('onError', err);
        },
    });
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#e1").select2({
            placeholder: "请输入或点击选择督察组",
            width: "100%",
            closeOnSelect: false,
            allowClear: true,
        });
    });
    function addHandle(data) {
        $(data).siblings("input").val($(data).val().join(","));
    }

    function handleAdd() {
        failure(".handleAdd",1)
        var inspectionId = $("input[name='inspectionId']").val()
        var content = $("textarea[name='content']").val()
        var mainName = $("input[name='mainName']").val()
        var file = $("input[name=file]").val()
        var gJFileName = $("input[name=fileName]").val()
        console.log(inspectionId,content,mainName)
        $.post("/taskCrucial/create",{"mainName":mainName,"content":content,"inspectionId":inspectionId,"gJFile":file,"gJFileName":gJFileName},function (res) {
            if(res){
                if(res.code == '200'){
                    alert('添加成功')
                    setTimeout(function () {
                        parent.close_current_app();
                    },50)
                } else {
                    alert('添加失败')
                }
                failure(".handleAdd",0)
            }
        })
    }
    function rightTipBOX(msg) {
        if(msg == undefined){
            msg = ''
        }
        $.gritter.add({
            title: "提示",
            text: msg
        });
    }
</script>
</body>
</html>
